﻿let pi = 3.1416
let g = 9.8;
///left
let leftBtn = document.querySelector("#jiasuspeed").querySelector("button");
let leftIpt = document.querySelector("#jiasuspeed").querySelectorAll("input");
let leftBtn2 = document.querySelector("#jiansujiasudu").querySelector("button");
let leftIpt2 = document.querySelector("#jiansujiasudu").querySelectorAll("input");
let leftBtn3 = document.querySelector("#jiansuzhuansu").querySelector("button");
let leftIpt3 = document.querySelector("#jiansuzhuansu").querySelectorAll("input");
////加速时间
window.addEventListener("load", function () {
    leftBtn.disabled = true;
})
let t = "";//////定位时间
let t0 = "";////加速时间
////将按钮设置为禁用，达到条件后启用
window.addEventListener('input', function () {
    if (!(leftIpt[0].value == "" || leftIpt[1].value == "" )) {
        leftBtn.disabled = false;
    }
    else {
        leftBtn.disabled = true;
    }
})
leftBtn.addEventListener("click", function () {
    t = parseFloat(leftIpt[0].value);
    t0 = t * parseFloat(leftIpt[1].value)/100;
    leftIpt[2].value = t0;
})
////减速机输出轴角加速度
window.addEventListener("load", function () {
    leftBtn2.disabled = true;
})
let β = "";
let Nmax = "";
window.addEventListener('input', function () {
    if (!(leftIpt2[0].value == "")) {
        leftBtn2.disabled = false;
    }
    else {
        leftBtn2.disabled = true;
    }
})
leftIpt2[0].addEventListener("input", function () {
    if (t0 == "") {
        swal("请先计算加速时间t0的值");
        leftIpt2[0].value = "";
        return;
    }
})
leftBtn2.addEventListener("click", function () {
    β = (parseFloat(leftIpt2[0].value) * pi) / (180 * (t0 * (t - t0)))
    leftIpt2[1].value = β;
    Nmax = (β * t0 / (2 * pi)) * 60;
    leftIpt3[0].value = Nmax;
})
////减速机输出转速
leftIpt3[0].addEventListener("input", function () {
    if (t0 == "" && β =="") {
        swal("请先计算加速时间t0、减速机输出轴角加速度的值");
        leftIpt3[0].value = "";
        return;
    }
    if (t0 == "" ) {
        swal("请先计算加速时间t0的值");
        leftIpt3[0].value = "";
        return;
    }
    if (β == "") {
        swal("减速机输出轴角加速度β的值");
        leftIpt3[0].value = "";
        return;
    }
})
/////right
let rightBtn = document.querySelector("#dianjijiasudu").querySelector("button");
let rightIpt = document.querySelector("#dianjijiasudu").querySelectorAll("input");
let rightBtn2 = document.querySelector("#dianjizhuansu").querySelector("button");
let rightIpt2 = document.querySelector("#dianjizhuansu").querySelectorAll("input");
let rightBtn3 = document.querySelector("#niuju").querySelector("button");
let rightIpt3 = document.querySelector("#niuju").querySelectorAll("input");
////电机输出轴角加速度
window.addEventListener("load", function () {
    rightBtn.disabled = true;
})
window.addEventListener('input', function () {
    if (!(rightIpt[0].value == "")) {
        rightBtn.disabled = false;
    }
    else {
        rightBtn.disabled = true;
    }
})
rightIpt[0].addEventListener("input", function () {
    if (β == "") {
        swal("减速机输出轴角加速度β的值");
        rightIpt[0].value = "";
        return;
    }
})
let βm;
let i = "";
let Nm = "";////电机输出轴转速
rightBtn.addEventListener("click", function () {
    i = parseFloat(rightIpt[0].value)
    βm = i * β;
    rightIpt[1].value = βm;
    Nm = Nmax *i;
    rightIpt2[0].value = Nm;
})
////电机输出轴转速
rightIpt2[0].addEventListener("input", function () {
    if (i == "" && Nmax =="") {
        swal("电机输出轴角加速度βm、减速机输出转速Nmax的值");
        rightIpt2[0].value = "";
        return;
    }
    if (i == "" ) {
        swal("电机输出轴角加速度βm的值");
        rightIpt2[0].value = "";
        return;
    }
    if ( Nmax == "") {
        swal("减速机输出转速Nmax的值");
        rightIpt2[0].value = "";
        return;
    }
})
/////电机输出扭矩
window.addEventListener("load", function () {
    rightBtn3.disabled = true;
})
window.addEventListener('input', function () {
    if (!(rightIpt3[0].value == "")) {
        rightBtn3.disabled = false;
    }
    else {
        rightBtn3.disabled = true;
    }
})
rightIpt3[0].addEventListener("input", function () {
    if (β == "") {
        swal("减速机输出轴角加速度β的值");
        rightIpt3[0].value = "";
        return;
    }
})
rightBtn3.addEventListener("click", function () {
    let T = parseFloat(rightIpt3[0].value) * β;
    rightIpt3[1].value = 2 * T;
})

